package com.app.action${mod};

import ${basePackage}.pojo.${className};

import java.util.Map;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.common.core.pojo.Pager;
import com.common.core.pojo.ParamMap;
import com.common.core.pojo.PermissionGroup;
import com.common.core.pojo.ResultMap;
import ${basePackage}.service${mod}.I${className}Service;

//${date}
@RequestMapping(value = ${className}Controller.PATH)
@RestController("${className}Controller")
public class ${className}Controller{
    private static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(${className}Controller.class);
    public static final String PATH = "${modPath}${className?lower_case}";
	public static final String defaultPermissionGroup=PATH+"/list.html";//默认权限组
	
    @Autowired
	private I${className}Service service;
	/*分页查询*/
	@RequestMapping(value = "/listPage", method = { RequestMethod.POST })
	@PermissionGroup({defaultPermissionGroup})
	public Map<String, Object> listPage(@RequestBody ParamMap<${className}> pm) {
		try {
			Pager<${className}> page = pm.getPage();
			page=service.queryByPage(page, pm);
			return ResultMap.get().successWithPager(page).toMap();
		} catch (Exception e) {
			log.error("list", e);
			return ResultMap.get().error(e).toMap();
		}
	}
	/*按id查询*/
	@RequestMapping(value = "/getById", method = { RequestMethod.GET,RequestMethod.POST })
	public ${className} getById(@RequestBody ParamMap<Object> pm) {
		return service.queryByParam(pm);
	}
    /*保存*/
	@RequestMapping(value = "/add", method = { RequestMethod.PUT })
	@PermissionGroup({defaultPermissionGroup})
	public Map<String, Object> add(@RequestBody ${className} vo) {
		try {
			service.save(vo);
			return ResultMap.get().setData("id", vo.getId()).success().toMap();
		} catch (Exception e) {
			log.error("add", e);
			return ResultMap.get().error(e).toMap();
		}
	}
    /*更新*/
	@RequestMapping(value = "/update", method = { RequestMethod.PUT })
	@PermissionGroup({defaultPermissionGroup})
	public Map<String, Object> update(@RequestBody ${className} vo) {
		try {
			service.update(vo);
			return ResultMap.get().success().toMap();
		} catch (Exception e) {
			log.error("update", e);
			return ResultMap.get().error(e).toMap();
		}
	}
    /* 删除 */
	@RequestMapping(value = "/deleteByIds", method = { RequestMethod.PUT })
	@PermissionGroup({defaultPermissionGroup})
	public Map<String, Object> deleteByIds(@RequestBody List<String> ids) {
		try {
			service.deleteByIds(ids);
			return ResultMap.get().success().toMap();
		} catch (Exception e) {
			log.error("delete", e);
			return ResultMap.get().error(e).toMap();
		}
	}
}